
using System;
using System.Data;
using System.Data.Odbc;
using Csla;
using Csla.Data;
using Csla.Validation;

namespace MinaspetroLibrary.UsuarioPack
{
    [Serializable()]
    public class UsuarioChildInfo : Csla.ReadOnlyBase<UsuarioChildInfo>
    {

        #region Business Properties and Methods

        //declare members

        private Guid _id = Guid.NewGuid();

        private string _nome = string.Empty;

        private string _login = string.Empty;

        private string _senha = string.Empty;

        private string _email = string.Empty;

        [System.ComponentModel.DataObjectField(true, false)]
        public Guid Id
        {
            get
            {
                CanReadProperty("Id", true);
                return _id;
            }
        }

        public string Nome
        {
            get
            {
                CanReadProperty("Nome", true);
                return _nome;
            }
        }

        public string Login
        {
            get
            {
                CanReadProperty("Login", true);
                return _login;
            }
        }

        public string Senha
        {
            get
            {
                CanReadProperty("Senha", true);
                return _senha;
            }
        }

        public string Email
        {
            get
            {
                CanReadProperty("Email", true);
                return _email;
            }
        }

        protected override object GetIdValue()
        {
            return _id;
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {
            //TODO: Define authorization rules in UsuarioChildInfo
            //AuthorizationRules.AllowRead("Id", "UsuarioChildInfoReadGroup");
            //AuthorizationRules.AllowRead("Nome", "UsuarioChildInfoReadGroup");
            //AuthorizationRules.AllowRead("Login", "UsuarioChildInfoReadGroup");
            //AuthorizationRules.AllowRead("Senha", "UsuarioChildInfoReadGroup");
            //AuthorizationRules.AllowRead("Email", "UsuarioChildInfoReadGroup");

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static UsuarioChildInfo GetUsuarioChildInfo(SafeDataReader dr)
        {
            return new UsuarioChildInfo(dr);
        }

        private UsuarioChildInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods

        #region Data Access

        #region Data Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);

            //load child object(s)
            FetchChildren(dr);

        }

        private void FetchObject(SafeDataReader dr)
        {
            _id = new Guid(dr["Id"].ToString());
            _nome = dr.GetString("Nome");
            _login = dr.GetString("Login");
            _senha = dr.GetString("Senha");
            _email = dr.GetString("Email");
        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //Data Access - Fetch
        #endregion //Data Access
    }
}
